#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 
# Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
# 

"""
File: unit3.py
Author: zhangyang(zhangyang40@baidu.com)
Date: 2018/2/2 0002 14:53
"""
import warnings

warnings.filterwarnings(action='ignore', category=UserWarning, module='gensim')
import logging

logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
from gensim import corpora, models

if __name__ == '__main__':
    dictionary = corpora.Dictionary.load('data/deerwester.dict')
    corpus = corpora.MmCorpus('data/deerwester.mm')
    tfidf = models.TfidfModel(corpus)
    doc_bow = [(0, 1), (1, 1)]
    print(tfidf[doc_bow])
    corpus_tfidf = tfidf[corpus]
    for doc in corpus_tfidf:
        print(doc)
    lsi = models.LsiModel(corpus_tfidf, id2word=dictionary, num_topics=2)
    corpus_lsi = lsi[corpus_tfidf]
    lsi.print_topics(2)
    for doc in corpus_lsi:
        print(doc)
    lsi.save('data/model.lsi')
    lsi = models.LsiModel.load('data/model.lsi')
# model = tfidfmodel.TfidfModel(bow_corpus, normalize=True)
# model = lsimodel.LsiModel(tfidf_corpus, id2word=dictionary, num_topics=300)
# model.add_documents(another_tfidf_corpus)
# lsi_vec = model[tfidf_vec]
# model.add_documents(more_documents)
# lsi_vec = model[tfidf_vec]
# model = rpmodel.RpModel(tfidf_corpus, num_topics=500)
# model = ldamodel.LdaModel(bow_corpus, id2word=dictionary, num_topics=100)
# model = hdpmodel.HdpModel(bow_corpus, id2word=dictionary)
